#pragma once
#include <boost/iostreams/categories.hpp>
#include "FileDeviceHandleFwd.h"
#include "ImportExport.h"

namespace ja2{ namespace vfs
{
	//! IO stream device implementation.
	class FileDevice
	{
		// Typedefs
	public:
		//! Type on which we are acting.
		typedef char char_type;
		//! Define category.
		struct category : 
			boost::iostreams::device_tag,
			boost::iostreams::peekable_tag,
			boost::iostreams::input_seekable,
			boost::iostreams::closable_tag
		{};

		//! Size type.
		typedef std::size_t size_type;
		//! Iterator type.
		typedef const char* iterator;
		
		// Attributes
	private:
		//! File device handle.
		FileDeviceHandlePtr_t m_pFileHandle;

		// Operations
	public:
		//! Read operation.
		JA2_VFS_API std::streamsize read(char* s, std::streamsize n);
		//! Write operation.
		JA2_VFS_API std::streamsize write(const char* s, std::streamsize n);
		//! Seek operation.
		JA2_VFS_API boost::iostreams::stream_offset seek(boost::iostreams::stream_offset off, std::ios_base::seekdir way);
		//! Open file if not opened already.
		JA2_VFS_API void open(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);
		//! Is device opened.
		JA2_VFS_API bool is_open() const;
		//! Close device.
		JA2_VFS_API void close();

		// Construction/Destruction
	public:
		//! Regular.
		JA2_VFS_API FileDevice(FileDeviceHandlePtr_t const &pFileHandle = FileDeviceHandlePtr_t());
	};
} /*vfs*/} /*ja2*/
